package design.patterns.singlemode;

/**
 * @Desc:   练习单例
 * @author: cww
 * @DateTime: 2020/6/9 8:27
 */

public class SingletonTest {
    public static SingletonTest singletonTest = new SingletonTest();

    private SingletonTest() {
    }
    public SingletonTest getInstance() {
        return singletonTest;
    }
}

class SingletonT2{
    public static SingletonT2 singletonT2;

    private SingletonT2() {
    }

    public synchronized static SingletonT2 getInsatance() {
        if(singletonT2==null){
            singletonT2 = new SingletonT2();
        }
        return singletonT2;
    }
}

class SingleInner{
    private static class Inner {
        public static SingleInner singleton = new SingleInner();
    }

    public static SingleInner getInstance() {
        return Inner.singleton;
    }
}